package com.learn.demo.mvc.action;

import com.learn.demo.service.DemoService;
import com.learn.springframework.annotation.Autowired;
import com.learn.springframework.annotation.Controller;
import com.learn.springframework.annotation.RequestMapping;
import com.learn.springframework.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
@RequestMapping("/demo")
public class DemoAction {


    @Autowired
    private DemoService demoService;

    @RequestMapping("/query")
    public void query(HttpServletRequest req, HttpServletResponse reps,
                      @RequestParam("name") String name, @RequestParam("id") String id) {
        String result = demoService.get(name);
        try {
            reps.getWriter().write(result);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @RequestMapping("/add")
    public void add(HttpServletRequest req, HttpServletResponse rep,
                    @RequestParam("a") Integer a, @RequestParam("b") Integer b) {
        try {
            rep.getWriter().write(a);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @RequestMapping("/remove")
    public void remove(HttpServletRequest req, HttpServletResponse rep,
                       @RequestParam("id") Integer id) {

    }
}
